home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / sources.arc / PIC_CODE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-02  |  5.1 KB  |  174 lines

  1. #include <osbind.h>
  2.  
  3. extern int filehandle;
  4.  
  5. extern int savepal[],pal4[],newpal[];
  6. extern   char     temp_[], /* Temp buffer where file is read in    */
  7.                  *hld,
  8.                  *iff_in, *iff_out;  /* Pointers for DEGAS unpack() routine    */
  9.  
  10.  
  11.  
  12. /* load degas compressed pics */
  13.  
  14. /************************/
  15. read_stuff(hold,adrr,which)
  16. char hold[];
  17. register char *adrr;
  18. int which;  
  19. /* if which = 1 then store palette into newpal*/
  20. /* which is the main pal of the game. If = neg then store */
  21. /* into pal 4. the alternate pals of the game */
  22.  
  23. {
  24.  char buf[130];
  25.  int lines,m,i;
  26.  static int only_once = 1;
  27.  
  28. filehandle = Fopen(hold,0); 
  29.  
  30. if( only_once )        /* save the palette ONCE!!! */
  31. {
  32. for(i=0; i<16;i++)
  33.  savepal[i]=Setcolor(i,-1);
  34. only_once = 0;
  35. }
  36.  
  37. /* read header data */
  38. i=Fread(filehandle,2L,buf);
  39.  
  40.  
  41. /* read 16 words of palette data into newpal array */
  42. if(which <= 0)
  43.  {
  44.  
  45.  if (which == 0)i = Fread(filehandle,32L,pal4);
  46.  }
  47. else
  48. i =Fread(filehandle,32L,newpal);
  49.  
  50.  
  51.  
  52.  
  53. i=Fread(filehandle,32000L,temp_);  /* read image onto back screen*/
  54. /* Close file */
  55. Fclose(filehandle);
  56.      lines = 200;                     /* Low, med-res    */
  57.                  iff_in  = temp_;                /* iff_in pts to temp_buf*/
  58.                  iff_out = adrr;      /* iff_out pts to pic_buffer*/
  59.                   do        
  60.          unpack(0);                                      /* Unpack a line at a time */
  61.                   while (--lines); 
  62.  
  63.  
  64.  /*v_gtext(handle,1,5,"             ");*/
  65.        
  66. }
  67. /************************/
  68.  
  69. /***********************/
  70.  
  71. /*---------------------------------------------------------------------------*/
  72. /*                             |--------- DEGAS ---------|            */
  73. /*                              UNCOMPRESSED   COMPRESSED            */
  74. /*                 NEO  low med mono   low med mono     TINY    */
  75. /*    typ...        0     1   2   3     4   5   6     7        */
  76.  
  77. /* Unpacks a single scan line & updates iff_in & iff_out global pointers
  78.  
  79.                      /    byt ==  0 to  127  copy next [byt+1] bytes
  80. Unpack routine --if-<    byt == -1 to -127  copy next byte [-byt+1] times
  81.                      \    byt == 128         NO-OP                            */
  82.  
  83. unpack(rez)
  84. int     rez;
  85.  
  86. {
  87.     register char     *src_ptr, *dst_ptr,           /* ptrs to source/dest */
  88.               byt, cnt;                     /* byt holds the ACTUAL compressed data code(control byte ) */
  89.     register int      minus128 = -128, 
  90.               len;                          
  91.     char                 linbuf[320];                            /* Oversize just in case! */
  92.     int                      llen;
  93.  
  94.  
  95.     if (rez < 2)     len = 160;
  96.     else             len = 80;
  97.     llen = len;
  98.     src_ptr = iff_in;           /* iff_in is ptr to compressed data */
  99.     dst_ptr = &linbuf[0];       /* linbuf WILL hold an ENTIRE Uncompressed scan line. 4 bitplanes * 80 = 320 max! */ 
  100.  
  101.     while (len > 0)
  102.    {
  103.             byt = *src_ptr++;       /* get byte value at address scr_ptr, THEN inc scr_ptr+1 */
  104.             if (byt >= 0)           /* If ctrl code >= 0 then use the next x+1 bytes*/
  105.     {
  106.                  ++byt;                 /* inc byt +1 */
  107.                   do 
  108.        {
  109.                         *dst_ptr++ = *src_ptr++;  /* get byte value from address source, and inc the 2 ptrs */
  110.                         --len;                    /* one byte down.. */
  111.                    }
  112.          while (--byt);           /* do this byt TIMES (remember byt here = byt+1 */
  113.              }
  114.              else 
  115.        if (byt != minus128)       /* else if ctrl code NOT = -128*/
  116.          {                        /*Then use the next byte -x+1 times, (-x) cause x will be negative and - - = + */
  117.                       cnt = -byt + 1;         /* cnt = -x + 1 */
  118.                       byt = *src_ptr++;       /* byt = THE very next byte past the ctrl code(or ctrl byte! */
  119.                        do {
  120.                                *dst_ptr++ = byt;  /* store that byte */
  121.                                --len;         
  122.                           }
  123.                while (--cnt);    /* keep doing it cnt times */
  124.                   }
  125.         }
  126.  
  127.     ilbm_st(linbuf, iff_out, rez);   /* convert the format line */
  128.     iff_in = src_ptr;                                    /* Update global pointers */
  129.     iff_out += llen;
  130.  
  131. }                                /* end of module uncompress() */
  132.  
  133. /*---------------------------------------------------------------------------*/
  134.  
  135. ilbm_st(src_ptr, dst_ptr, rez)           /* Convert ILBM format line to ST format */
  136. int         *src_ptr, *dst_ptr, rez;
  137. {
  138.     int         x, *p0_ptr, *p1_ptr, *p2_ptr, *p3_ptr;
  139.  
  140.     if (rez==0) 
  141.  {                                                     /* Low-res */
  142.   
  143.         p0_ptr = src_ptr;
  144.         p1_ptr = src_ptr + 20;
  145.         p2_ptr = src_ptr + 40;
  146.         p3_ptr = src_ptr + 60;
  147.         for (x=0; x<20; ++x)
  148.   {
  149.                *dst_ptr++ = *p0_ptr++;
  150.                *dst_ptr++ = *p1_ptr++;
  151.                *dst_ptr++ = *p2_ptr++;
  152.                *dst_ptr++ = *p3_ptr++;
  153.           }
  154.     } 
  155.  else if (rez==1) 
  156.   {                                            /* Med-res */
  157.            p0_ptr = src_ptr;
  158.            p1_ptr = src_ptr + 40;
  159.            for (x=0; x<40; ++x)
  160.     {
  161.                  *dst_ptr++ = *p0_ptr++;
  162.                  *dst_ptr++ = *p1_ptr++;
  163.             }
  164.     }
  165.     else 
  166.      {                                                   /* Monochrome */
  167.               for (x=0; x<40; ++x)
  168.                   *dst_ptr++ = *src_ptr++;
  169.          }
  170.  
  171.  }
  172. /*---------------------------------------------------------------------------*/
  173.  
  174.